package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Role;
import org.akomantoso.core.data.group.ANheaderInline;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitable;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element party is an inline element within judgements to identify where the document defines one of the parties.
 * 
 * <pre>
 * 	<xsd:element name="party">
 * 		<xsd:complexType mixed="true">
 * 			<xsd:complexContent>
 * 				<xsd:extension base="inlinereqreq">
 * 					<xsd:attributeGroup ref="role"/>
 * 				</xsd:extension>
 *			</xsd:complexContent>
 *		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class Party extends InlineReqReqType implements Role , ANheaderInline , AKVisitable{

	public static final String ELEMENT = "party";
	
	// Optional
	private String _as;
	
	/**
	 * @see org.akomantoso.core.data.attribute.Role#getAs()
	 */
	@Override
	public String getAs() {
		return _as;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Role#getAs()
	 */
	@Override
	public void setAs(String as) {
		_as = as;
	}

	/**
	 * @see org.akomantoso.core.data.InlineReqReqType#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <E extends Output> void writeExternal(E out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeAttribute(out, Role.ATTRIBUTE, _as);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.visitor.AKVisitable#accept(org.akomantoso.core.visitor.AKVisitor)
	 */
	@Override
	public void accept(AKVisitor visitor) {
		if (visitor.visitBegin(this)) {
			internalAccept(visitor);
			visitor.visitEnd(this);
		}
		
	}
	
}